<template>
    <div>
        <el-container class="form-container">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>Demo</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="submitForm">保存</el-button>
                </div>
                <div >
                   <el-form  :rules="rules"  ref="form"   :model="form" size="small" label-width="120px">
                        <el-row>
                                  <el-col :span="12">
                                      <el-form-item  label="分类名称"  prop="fdName" >
                                          <el-input class="input" v-model="form.fdName" ></el-input>
                                      </el-form-item>
                                  </el-col>
                                  <el-col :span="12">
                                      <el-form-item  label="上级分类名称"  prop="fdParentName">
                                        <sys-category-select-tree
                                          v-model="form.fdParentName"
                                          :id.sync="form.fdParentId"
                                          :modelName="form.fdModelName"
                                          :modelKey="form.fdKey"
                                          clearable
                                        />
                                      </el-form-item>
                                  </el-col>
                                </el-row>
                                <el-row>
                                <el-col :span="12">
                                    <el-form-item  label="排序号"  prop="fdOrder">
                                        <el-input-number v-model="form.fdOrder" :min="1" ></el-input-number>
                                    </el-form-item>
                                </el-col>
                                </el-row>
                   </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import SysCategorySelectTree from "@/components/common/form/FancySysCategorySelectTree";
import dateUtils from '@/utils/dateUtils';
import formUtils from '@/utils/formUtils';
export default {
    name: "SysCategoryMainAdd",
    components: {
        SysCategorySelectTree
    },
    data() {
      return {
        form: {
            fdId:'',
            fdCreateTime:'',
            fdName:'',
            fdParentId:'',
            fdParentName:'',
            fdModelName:'',
            fdKey:'',
            fdOrder:'',
        },
        rules:{
            fdName :[{required: true, message: '请输入分类名称', trigger: 'blur'}],
        },
        optionData:[],
        props: {
          label: "name",
          value: "id",
        }
      }
    },
    created() {
        this.initParam();
    },
    methods: {
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    this.fullscreenLoading = true;
                    let forms = formUtils.convertToModel(this.form);
                    this.$put('/api/sys/category/sys_category_main',forms).then((res) => {
                        this.fullscreenLoading = false;
                        if(res.status==1){
                            this.$message({
                                message: res.message,
                                type: 'success',
                                onClose: function (){
                                    window.close();
                                }
                            });
                        }else{
                            this.$message.error(res.message);
                        }
                    });

                }
            });
        },
        initParam() {
            this.form.fdParentId = this.$route.query.parentId;
            this.form.fdParentName = this.$route.query.parentName;
            this.form.fdModelName = this.$route.query.modelName;
            this.form.fdKey = this.$route.query.modelKey;
            let fdId = this.$route.query.id;
            if(formUtils.isNotEmpty(fdId)){
              this.fullscreenLoading = true;
              this.$fetch('/api/sys/category/sys_category_main',{
                  id:fdId
              }).then((res) => {
                  formUtils.convertToForm(res.data,this.form);
                  this.fullscreenLoading = false;
              });
            }
        }
    },
    watch:{
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>